#!/bin/zsh

# start the keyboard combination daemon
sxhkd -c ~/.config/berry/sxhkdrc &

# Set decoration geometry
berryc border_width       0
berryc inner_border_width 0
berryc title_height       26
berryc top_gap            26

# Set decoration colors
berryc focus_color         292D3E
berryc unfocus_color       292D3E
berryc inner_focus_color   56aa79
berryc inner_unfocus_color 565679
berryc text_focus_color    222222
berryc text_unfocus_color  eeeeee

# Other options
berryc smart_place            "true"
berryc draw_text              "true"
berryc edge_lock              "true"
berryc set_font               "Dina-9"


# set the screen resolution if you are in a vm
xrandr --listmonitors | grep -q 'Virtual-1 1024/271x768/203+0+0' &&
	xrandr --output Virtual-1 --mode 1366x768

# set the wallpaper
feh --randomize --bg-fill ~/Pictures/wall

# start the bar
batterysec(){
zsh -c '
GRML_BATTERY_LEVEL=""
local batteries bat capacity
batteries=`echo /sys/class/power_supply/BAT*`
if (( $#batteries > 0 )) ; then
    for bat in $batteries ; do
        if [[ -e $bat/capacity ]]; then
            capacity=$(< $bat/capacity)
        else
            typeset -F energy_full=$(< $bat/energy_full)
            typeset -F energy_now=$(< $bat/energy_now)
            typeset -i capacity=$(( 100 * $energy_now / $energy_full))
        fi
        case $(< $bat/status) in
        Charging)
            GRML_BATTERY_LEVEL+="^"
            ;;
        Discharging)
            if (( capacity < 20 )) ; then
                GRML_BATTERY_LEVEL+="%{B#AA7766} v"
            else
                GRML_BATTERY_LEVEL+="v"
            fi
            ;;
        *) # Full, Unknown
            GRML_BATTERY_LEVEL+="="
            ;;
        esac
        GRML_BATTERY_LEVEL+="${capacity}%%"
    done
fi
echo "$GRML_BATTERY_LEVEL %{B#292D3E}"
' 2>/dev/null
}

if which lemonbar
then
pkill -x lemonbar || true
while sleep 1
do
	echo ' %{c}'`date -R`' %{r}'`batterysec`' '`uptime | cut -d' ' -f12 | cut -b-4`' '
done | lemonbar -g x26 -B '#292D3E' -F '#CCCCCC' -f 'Fira Code:size=9:antialias=true' &
fi



